package com.itheima.tilas.mapper;

import com.itheima.tilas.dto.SelectAllDeptDTO;
import com.itheima.tilas.entity.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 部门映射
 * @author 132
 */
@Mapper
public interface DeptMapper {

    @Select("select id,name,update_time from dept order by update_time desc ")
    List<SelectAllDeptDTO> selectAll();

    @Select("select * from dept where id=#{id}")
    Dept selectById(@Param("id") Integer id);

    @Select("select id,name from dept where id!=#{id} and name=#{name}")
    SelectAllDeptDTO selectByIdAndName(@Param("id") Integer id,@Param("name") String name);

    @Insert("insert into dept (name,update_time,create_time) values (#{d.name},#{d.updateTime},#{d.createTime})")
    int insertDept(@Param("d") Dept dept);

    @Delete("delete from dept where id = #{id}")
    int deleteById(@Param("id") Integer id);

    @Update("update dept set name = #{u.name},update_time = #{u.updateTime} where id=#{u.id}")
    int updateById(@Param("u")Dept up);

    int deleteBatchByIds(@Param("ids") List<Integer> ids);

    int insertBatch(@Param("depts") List<Dept> depts);
}
